package com.dormitory123.millet.dao.Impl;

import com.dormitory123.millet.dao.BaseDao;
import com.dormitory123.millet.dao.OrderItemDao;
import com.dormitory123.millet.pojo.OrderItem;

import java.util.List;

/**
 * @author yanhuanzhan
 * @date 2022/1/6 - 19:59
 */
public class OrderItemDaoImpl extends BaseDao implements OrderItemDao {
    @Override
    public void createOrderItem(OrderItem orderItem) {
        String sql = "INSERT INTO t_order_item(name,count,price,total_price,order_id,img_path) VALUES(?,?,?,?,?,?)";
        update(sql, orderItem.getName(), orderItem.getCount(), orderItem.getPrice(), orderItem.getTotalPrice(), orderItem.getOrderId(),orderItem.getImgPath());
    }

    @Override
    public List<OrderItem> queryOrderItemsByOrderId(String orderId) {
        String sql = "SELECT `id`,`name`,`count`,`price`,`total_price` totalPrice,`img_path` imgPath,`order_id` orderId FROM t_order_item WHERE order_id=?";
        return queryForList(OrderItem.class, sql, orderId);
    }

}
